import { Controller, Get, Post, Body, Request, UseGuards } from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { AppService } from './app.service'
import { AuthService } from './auth/auth.service'
import { CreateUserDto } from './database/user/dto/create-user.dto'

@Controller()
export class AppController {
  constructor(
    private readonly appService: AppService,
    private readonly authService: AuthService) { }


  // 用户注册
  @Post('register')
  register(@Body() userInfo: CreateUserDto) {
    return this.appService.register(userInfo);
  }


  // 用户登录
  @UseGuards(AuthGuard('local'))
  @Post('login')
  async login(@Request() req) {    
    return this.authService.login(req.user)
  }

}
